.class public Lcom/zuiapps/suite/utils/security/HashUtil;
.super Ljava/lang/Object;
.source "HashUtil.java"


# static fields
.field private static hexChar:[C


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 9
    const/16 v0, 0x10

    new-array v0, v0, [C

    fill-array-data v0, :array_a

    sput-object v0, Lcom/zuiapps/suite/utils/security/HashUtil;->hexChar:[C

    return-void

    :array_a
    .array-data 2
        0x30s
        0x31s
        0x32s
        0x33s
        0x34s
        0x35s
        0x36s
        0x37s
        0x38s
        0x39s
        0x61s
        0x62s
        0x63s
        0x64s
        0x65s
        0x66s
    .end array-data
.end method

.method public constructor <init>()V
    .registers 1

    .prologue
    .line 11
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 12
    return-void
.end method

.method public static getFileMD5(Ljava/lang/String;)Ljava/lang/String;
    .registers 4
    .param p0, "filename"    # Ljava/lang/String;

    .prologue
    .line 15
    const-string v1, ""

    .line 17
    .local v1, "str":Ljava/lang/String;
    :try_start_2
    const-string v2, "MD5"

    invoke-static {p0, v2}, Lcom/zuiapps/suite/utils/security/HashUtil;->getHash(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    :try_end_7
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_7} :catch_9

    move-result-object v1

    .line 21
    :goto_8
    return-object v1

    .line 18
    :catch_9
    move-exception v0

    .line 19
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_8
.end method

.method public static getFileSHA1(Ljava/lang/String;)Ljava/lang/String;
    .registers 4
    .param p0, "filename"    # Ljava/lang/String;

    .prologue
    .line 25
    const-string v1, ""

    .line 27
    .local v1, "str":Ljava/lang/String;
    :try_start_2
    const-string v2, "SHA1"

    invoke-static {p0, v2}, Lcom/zuiapps/suite/utils/security/HashUtil;->getHash(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    :try_end_7
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_7} :catch_9

    move-result-object v1

    .line 31
    :goto_8
    return-object v1

    .line 28
    :catch_9
    move-exception v0

    .line 29
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_8
.end method

.method private static getHash(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .registers 7
    .param p0, "fileName"    # Ljava/lang/String;
    .param p1, "hashType"    # Ljava/lang/String;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 35
    new-instance v1, Ljava/io/FileInputStream;

    invoke-direct {v1, p0}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V

    .line 36
    .local v1, "fis":Ljava/io/InputStream;
    const/16 v4, 0x400

    new-array v0, v4, [B

    .line 37
    .local v0, "buffer":[B
    invoke-static {p1}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;

    move-result-object v2

    .line 38
    .local v2, "md5":Ljava/security/MessageDigest;
    const/4 v3, 0x0

    .local v3, "numRead":I
    :goto_e
    invoke-virtual {v1, v0}, Ljava/io/InputStream;->read([B)I

    move-result v3

    if-lez v3, :cond_19

    .line 39
    const/4 v4, 0x0

    invoke-virtual {v2, v0, v4, v3}, Ljava/security/MessageDigest;->update([BII)V

    goto :goto_e

    .line 42
    :cond_19
    invoke-virtual {v1}, Ljava/io/InputStream;->close()V

    .line 43
    invoke-virtual {v2}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v4

    invoke-static {v4}, Lcom/zuiapps/suite/utils/security/HashUtil;->toHexString([B)Ljava/lang/String;

    move-result-object v4

    return-object v4
.end method

.method private static toHexString([B)Ljava/lang/String;
    .registers 5
    .param p0, "b"    # [B

    .prologue
    .line 47
    new-instance v1, Ljava/lang/StringBuilder;

    array-length v2, p0

    mul-int/lit8 v2, v2, 0x2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(I)V

    .line 48
    .local v1, "sb":Ljava/lang/StringBuilder;
    const/4 v0, 0x0

    .local v0, "i":I
    :goto_9
    array-length v2, p0

    if-ge v0, v2, :cond_27

    .line 49
    sget-object v2, Lcom/zuiapps/suite/utils/security/HashUtil;->hexChar:[C

    aget-byte v3, p0, v0

    and-int/lit16 v3, v3, 0xf0

    ushr-int/lit8 v3, v3, 0x4

    aget-char v2, v2, v3

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    .line 50
    sget-object v2, Lcom/zuiapps/suite/utils/security/HashUtil;->hexChar:[C

    aget-byte v3, p0, v0

    and-int/lit8 v3, v3, 0xf

    aget-char v2, v2, v3

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    .line 48
    add-int/lit8 v0, v0, 0x1

    goto :goto_9

    .line 53
    :cond_27
    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    return-object v2
.end method
